package com.foton.springbootdemo.event.impl;


import com.yunjin.equirement.common.event.DomainEvent;
import com.yunjin.equirement.common.event.DomainEventBus;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

/**
 * .
 * <p>
 * 北京云锦汇智信息技术有限公司 版权所有Copyright (C) 2022
 * </p>
 * <p>
 * 简介说明: 事件总线的简单实现，只能在单体架构中应用
 *
 * @author 任璞
 * @since 2025/11/20 11:39
 */

@Component
public class SimpleEventImpl implements DomainEventBus, ApplicationContextAware {

    private ConfigurableApplicationContext applicationContext;

//    @Resource
//    private MQProducer mqProducer;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=(ConfigurableApplicationContext)applicationContext;
    }


    @Override
    public void post(DomainEvent event) {
     applicationContext.publishEvent(event);
     // TODO 此处可进行跨服务，消息交互投递到MQ
//        mqProducer.send();
    }

    @Override
    public void register() {

    }



}
